package com.jie.demo1.controller;
/*
package com.jie.demo1.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jie.demo1.Sservice.UserService;
import com.jie.demo1.pojo.QueryPage;
import com.jie.demo1.pojo.Result;
import com.jie.demo1.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

import java.util.List;
@RestController
@CrossOrigin(origins = "http://localhost:5173/")
public class hello {
    @Autowired
    private UserService userService;
    @CrossOrigin(origins = "http://localhost:5173/")
    @RequestMapping("/h")
    public String H() {
        return "hellow";
    }

    @CrossOrigin(origins = "http://localhost:5173/")
    @PostMapping("/list")
    public Result<U> H1() {
        try {
            List<User> list = userService.list();
            return Result.success(list);
        } catch (Exception e) {
            // 这里可以根据具体的异常类型进行更细致的处理，比如记录日志等
            // 暂时先统一返回一个通用的失败状态码和消息
            return Result.fail();
        }
    }

    //新增
    @CrossOrigin(origins = "http://localhost:5173/")
    @PostMapping("/save")
    public Result<U> saveUser(@RequestBody User user){

        return Result.success(userService.save(user));
    }
    @CrossOrigin(origins = "http://localhost:5173/")
    //删除
    @PostMapping("/delete")
    public  Result<U> deleteUser(@RequestBody int id){
        try {
            boolean b = userService.removeById(id);
            if (b){
                return Result.success();
            } return Result.fail("不存在id=="+id+"的数据");
        } catch (Exception e) {
            return Result.fail();
        }
    }

    //修改
    @PostMapping("/modify")
    public Result<U> modifyUser(@RequestBody User user){
        return Result.success(userService.updateById(user));//虽然名为updateById，但是需要传入的参数是一个实体类对象
    }

    //登陆
    @PostMapping("/login")
    public Result<U> login(@RequestBody User user){
        // 创建查询条件
        LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
        userLambdaQueryWrapper.eq(User::getNo, user.getNo())
                .eq(User::getPassword, user.getPassword());
        // 执行查询
        List<User> userList = userService.list(userLambdaQueryWrapper);
        System.out.println(userList);
        // 检查查询结果并返回相应的结果
        return userList != null && !userList.isEmpty() ?
                Result.success(userList) :
                Result.fail("登录失败，用户不存在或密码错误");
    }


    //添加·或者修改
    @PostMapping("/saveOrUpdate")
    public Result<U> saveOrUpdateUser(@RequestBody User user){
        //如果传入的user有一个id则为修改，如果没有就是新增
       return Result.success(userService.saveOrUpdate(user));

    }

    //模糊查询，传入某个参数，查询对应数据
    @PostMapping ("/listP")
    public Result<U> listP(@RequestBody User user) {
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(User::getName,user.getName());
        return Result.success(userService.list(lambdaQueryWrapper));
    }


    @CrossOrigin(origins = "http://localhost:5173/")
    @PostMapping("/autoListPage")
    public Result<U> listPage(@RequestBody QueryPage queryPage){
        System.out.println(queryPage);
        HashMap param = queryPage.getParam();
        //param.get("name").toString();
        IPage<User> userPage = new Page<>(queryPage.getPageNum(),queryPage.getPageSize());//当前页，每页多少条记录
        if (param.get("name") !=null){
            LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();//

            userLambdaQueryWrapper.like(User::getName, param.get("name"));

            IPage<User> result = userService.page(userPage,userLambdaQueryWrapper);
            long total = result.getTotal();
            return Result.success(result.getRecords(),total);
        }
        IPage<User> result = userService.page(userPage);
        long total = result.getTotal();
        System.out.println(total);  //一共多少条
        return Result.success(result.getRecords(),total);
    }


    @PostMapping("/manualListPage")
    public Result<U> manualListPage(@RequestBody QueryPage queryPage){
        IPage<User> userPage = new Page<>(queryPage.getPageNum(),queryPage.getPageSize());//当前页，每页多少条记录
        IPage result =userService.manualListPage(userPage);
        System.out.println("手动分页");
        return Result.success(result.getRecords(), result.getTotal());
    }
}

*/
public class hello {
}